import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_bmfbase/BaiduMap/bmfmap_base.dart'
    show BMFMapSDK, BMF_COORD_TYPE;
import 'package:flutter_bmflocation/bdmap_location_flutter_plugin.dart';
import 'package:fly_car/routes.dart';

void main() {
  //兼容老项目
  WidgetsFlutterBinding.ensureInitialized();
  setBaiDuSdk();
  runApp(MyApp());
}

//设置百度的SDK
setBaiDuSdk() {
  //动态申请定位权限
  if (Platform.isIOS) {
    BMFMapSDK.setApiKeyAndCoordType(
        'Y1QyrMffUU2L3kiC4HnTccFjOGdqvmsz', BMF_COORD_TYPE.BD09LL);
    LocationFlutterPlugin.setApiKey("Y1QyrMffUU2L3kiC4HnTccFjOGdqvmsz");
    //设置iOS端AK, Android端AK可以直接在清单文件中配置
  } else if (Platform.isAndroid) {
    BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL);
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Fly Car',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      initialRoute: "/main",
      onGenerateRoute: onGenerateRoute,
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
    );
  }
}
